use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct WebRTCDialMessage {
    #[serde(rename = "candidates")]
    pub candidates: Vec<String>,
    #[serde(rename = "local_description")]
    pub local_description: String,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct WebRTCDialResponseMessage {
    #[serde(rename = "candidates")]
    pub candidates: Vec<String>,
    #[serde(rename = "local_description")]
    pub local_description: String,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
#[serde(tag = "type", content = "data")]
pub enum WebRTCMessage {
    #[serde(rename = "dial")]
    Dial(WebRTCDialMessage),
    #[serde(rename = "dial_response")]
    DialResponse(WebRTCDialResponseMessage),
}

impl WebRTCMessage {}

impl From<&String> for WebRTCMessage {
    fn from(msg: &String) -> Self {
        let msg_str = msg.as_str();
        serde_json::from_str(msg_str).expect("signal message unmarshal")
    }
}

impl From<&WebRTCMessage> for String {
    fn from(msg: &WebRTCMessage) -> Self {
        serde_json::to_string(msg).expect("signal message marshal")
    }
}
